<?php



set_time_limit(0);

function genUserData($email)
{
	$data = array();
	$data["email"] = $email;
	$data["gold"] = 10000;
	$data["mana"] = 10000;
	$data["level"] = 1;
	$data["lastActiveTime"] = time();
	$data["buildings"] = array();
	
	for ( $i = 0; $i < 10; $i++ )
	{	
		$vo = new stdClass();
		$vo->mana = 1000;
		$vo->gold = 1000;
		$vo->level = 1;
		$vo->costGold = 1000;
		$vo->costMana = 1000;
		$vo->increasing = true;
		$vo->increaseTime = 0;
		
		array_push( $data["buildings"], $vo );
	}
	
	return $data;
}

function writeBigFile($obj)
{
	file_put_contents("big.txt", serialize($obj));
}

function readBigFile()
{
	return unserialize(file_get_contents("big.txt"));
}

// build big object
$time = 0;
$data = array();
$i = 1000;

while( --$i > -1 )
{
	$email = "fake_".$i."@gmail.com";
	$data[$email] = genUserData($email);
}


$time = microtime();
writeBigFile($data);
echo microtime() - $time, "<br/>";

$time = microtime();
readBigFile();
echo microtime() - $time, "<br/>";






?>